package com;

import com.ip.IPHandlerInterceptor;
import com.properties.WebProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
public class Application implements WebMvcConfigurer {

    @Autowired
    private WebProperties webProperties;
    /**
     * 添加mvc请求拦截器
     * @param registry registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new IPHandlerInterceptor(webProperties))
                .addPathPatterns(webProperties.getIpWhitelistUrl());
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }
}
